{{ if .IsEdit}}
{{$contentitle := printf "%s(%s)" .Tracing.Key .Tracing.Title}}
{{addToMap . "ContentTitle" $contentitle}}
{{else}}
{{addToMap . "ContentTitle" "新增监控点"}}
{{end}}


<div class="alert alert-danger alert-dismissable hide" id="formErrAlarm">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
    <h4><i class="icon fa fa-ban"></i> 数据填写错误</h4>
    请根据提示完善数据信息。
</div>
<div class="box box-info">
    <div class="box-header with-border">
      <h3 class="box-title">监控点信息</h3>
      {{if .IsEdit}}
      <div class="box-tools pull-right">
      <a href="/project/{{.Project.Id}}/tracing/{{.Tracing.Id}}/warnings?listsubmenu={{.SubMenu}}">查看报警记录</a>
      </div>
      {{end}}
    </div><!-- /.box-header -->
    <!-- form start -->
    <form class="form-horizontal" method="POST">
      <div class="box-body">
        <div class="form-group center-block">
          <label for="tracing-key" class="col-sm-4 control-label">监控点</label>
          <div class="col-sm-4">
            <input type="text" class="form-control" id="tracing-key" name="Key" value="{{.PostTracingMap.Key}}" placeholder="监控点(英文标识)" {{if .IsEdit}}disabled="true"{{end}}>
          </div>
        </div>
        {{if .IsEdit}}
        <div class="form-group">
          <label for="tracingstatus" class="col-sm-4 control-label">状态</label>
          <div class="col-sm-4">
            {{$isRunning := eq .Tracing.Status 10}}
            {{if $isRunning}}
            <span id="tracing-status-text" style="color:green">监控中</span>
            {{else}}
            <span id="tracing-status-text" style="color:red">停止</span>
            {{end}}
            <button id="tracing-status-btn" class="btn {{if $isRunning}}btn-danger{{else}}btn-primary{{end}}" style="margin-left:20px;">{{if $isRunning}}停止{{else}}监控{{end}}</button>
          </div>
        </div>
        {{end}}
        <div class="form-group">
          <label for="tracing-title" class="col-sm-4 control-label">中文名称</label>
          <div class="col-sm-4">
            <input type="text" class="form-control" name="Title" id="tracing-title" value="{{.PostTracingMap.Title}}" placeholder="中文名称">
          </div>
        </div>
        <div class="form-group">
          <label for="tracing-type" class="col-sm-4 control-label">类型</label>
          <div class="col-sm-4">
          <label class="radio-inline">
              <input type="radio" name="Type" id="tracing-type-trigger" {{with .PostTracingMap.Type}}{{if eq . 1}}checked{{end}}{{else}}checked{{end}} value="1">
              直接触发
          </label>
          <label class="radio-inline">
              <input type="radio" name="Type" id="tracing-type-timer" {{with .PostTracingMap.Type}}{{if eq . 2}}checked{{end}}{{end}} value="2">
              定时监控
          </label>
          </div>
        </div>
        <div class="form-group">
          <label for="tracing-tracingtime" class="col-sm-4 control-label">定时监控规则</label>
          <div class="col-sm-4">
            <input type="text" class="form-control" name="TracingTime" id="tracing-tracingtime" value="{{.PostTracingMap.TracingTime}}" placeholder="请符合crontab规则">
          </div>
        </div>
      </div><!-- /.box-body -->
      <div class="box-footer">
      {{if .IsEdit}}
        <button type="submit" class="btn btn-primary center-block">修改</button>
      {{else}}
        <button type="submit" class="btn btn-primary center-block">提交</button>
      {{end}}
      </div><!-- /.box-footer -->
    </form>
</div>
<script type="text/javascript">


$(function(){

$('#tracing-status-btn').on("click", function(e){
  e.preventDefault();
  var me = $(this);
  if (me.attr("isloading") == "yes") {
    return;
  }
  me.attr("isloading", "yes");
  var status = 10;//默认正常
  if (me.hasClass("btn-danger")) {
    status = -1;//停止
  }


  $.post("/project/{{.Project.Id}}/tracing/{{.Tracing.Id}}/ajaxSetStatus", {"status":status}, function(repo){
    if (repo.code != 0) {
      alert("系统错误");
      me.attr("isloading", "no");
      return;
    }

    if (me.hasClass("btn-danger")) {
      me.removeClass("btn-danger");
      me.addClass("btn-primary");
      me.text("监控");
      $('#tracing-status-text').html("停止").css("color", "red");
    } else {
      me.removeClass("btn-primary");
      me.addClass("btn-danger");
      me.text("停止");
      $('#tracing-status-text').html("监控中").css("color", "green");
    }
    me.attr("isloading", "no");
    return;
  }, "json");
});

{{if .FormErrs}}
var formErrs = {{.FormErrsJson}};
showFormErrsAndAlarms(formErrs, function(f){
    return $("input[name="+f+"]");
}, function(input, f){
    return input.parent().parent();
});
{{end}}


});

</script>